package win.bigwhale.sudoku.logic;

import java.awt.Point;

import javafx.scene.text.Text;
import win.bigwhale.sudoku.SudokuUtil;
import win.bigwhale.sudoku.view.Playfield;

public class SudokuNumber {
	private Point numberPosition = null;
	private int number = 0;
	private boolean isOrig = false;
	private Text numText = null;
	public SudokuNumber(Point point, int num, boolean isOrig) {
		numberPosition = new Point(point);
		number = num;
		this.isOrig = isOrig;
	}

	public void createNumText() {
		numText = new Text("" + number);
		numText.setScaleX(2.5);
		numText.setScaleY(2.5);

		if (isOrig) {
			numText.setFill(SudokuUtil.JIAOCHA_COLOR);
		} else {
			numText.setFill(SudokuUtil.CHANGPAN_COLOR);
		}
		Point northEastPoint = getNumTextNorthWest();
		numText.setLayoutX(northEastPoint.x);
		numText.setLayoutY(northEastPoint.y);
	}
	
	public Text getNumText() {
		return numText;
	}

	public int getRow() {
		return numberPosition.y;
	}
	
	public int getColumn() {
		return numberPosition.x;
	}
	
	public int getRect() {
		return numberPosition.y / 3 * 3 + numberPosition.x / 3;
	}

	public int getNumber() {
		return number;
	}
	
	public Point getNumberPosition() {
		return numberPosition;
	}

	@Override
	public String toString() {
		return numberPosition.toString() + " " + new Integer(number).toString();
	}

	public boolean isOrig() {
		return isOrig;
	}

	public Point getNumTextNorthWest() {
		Point northWestPoint = new Point();
		
		northWestPoint.x = getColumn() * 50 + getColumn() / 3 + 20;
		northWestPoint.y = getRow() * 50 + getRow() / 3 + 33;
		
		return northWestPoint;
	}

	public void removeSelf() {
		numText.setVisible(false);
		Playfield.getPlayField().removeNode(numText);
	}

	public void setVisible(boolean visible) {
		numText.setVisible(visible);
	}

	public void addSelf() {
		Playfield.getPlayField().addNode(numText);
	}
}
